package com.chain.BrotherExchange.ui.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.chain.BrotherExchange.C;
import com.chain.BrotherExchange.R;
import com.chain.BrotherExchange.data.model.LegalTenderAssetsList;
import com.chain.BrotherExchange.ui.activity.MonetaryDetailsActivity;

import java.util.List;

/**
 * 法币资产
 */
public class LegalTenderAssetsListAdapter extends RecyclerView.Adapter<LegalTenderAssetsListAdapter.ViewHolder> {

    private final List<LegalTenderAssetsList.DataBean.ListBean> mAssetsList;

    public LegalTenderAssetsListAdapter(List<LegalTenderAssetsList.DataBean.ListBean> assetsList) {
        this.mAssetsList = assetsList;
    }

    @NonNull
    @Override
    public LegalTenderAssetsListAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new ViewHolder(LayoutInflater.from(viewGroup.getContext())
                .inflate(R.layout.item_my_assets, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull LegalTenderAssetsListAdapter.ViewHolder holder, int i) {
        LegalTenderAssetsList.DataBean.ListBean listBean = mAssetsList.get(i);
        holder.mCoinTypeText.setText(listBean.getToken_name());
        holder.mBalanceText.setText(listBean.getBalance());
        holder.mFreezeText.setText(listBean.getFreeze());
        holder.mValuationText.setText(listBean.getValuation());
        holder.itemView.setOnClickListener(v ->
                MonetaryDetailsActivity.launch(holder.mBalanceText, holder.mFreezeText,
                        holder.mValuationText, holder.mCoinTypeText, listBean.getToken_id(),
                        C.VALUE_LEGAL_CURRENCY_TYPE)
        );
    }

    @Override
    public int getItemCount() {
        return mAssetsList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private final TextView mValuationText;
        private final TextView mBalanceText;
        private final TextView mFreezeText;
        private final TextView mCoinTypeText;

        ViewHolder(@NonNull View itemView) {
            super(itemView);
            mValuationText = itemView.findViewById(R.id.valuation_text);
            mBalanceText = itemView.findViewById(R.id.balance_text);
            mFreezeText = itemView.findViewById(R.id.freeze_text);
            mCoinTypeText = itemView.findViewById(R.id.coin_type_text);
        }
    }
}
